package main

import (
	"flag"
	"fmt"
	"os"
	"os/signal"
	"strings"
	"syscall"

	"goweb/ext/setup"
)

func main() {
	cfg := flag.String("c", "./conf/config.json", "configuration file")
	flag.Parse()
	dir, _ := os.Getwd()
	join := strings.Join([]string{dir, *cfg}, "/")
	fmt.Println(join)
	setup.SetUp(join)

	//var arguments []string
	//arguments := make([]string, 10)
	//if len(os.Args) > 1 {
	//	for _, value := range os.Args {
	//		arguments = append(arguments, value)
	//	}
	//}

	//if len(os.Args) > 1 {
	//	err = service.Control(ser, arguments[len(arguments)-1])
	//	if err != nil {
	//		fmt.Println("生成服务异常", err)
	//	}
	//} else {
	//	ser.Run()
	//}

	setup.Web()
	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT, syscall.SIGHUP)
	for {
		s := <-c
		switch s {
		case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
			fmt.Println("goweb exit...")
			return
		case syscall.SIGHUP:
		default:
			return
		}
	}
}
